SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[TB_User]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[TB_User](
	[n4UserNo] [int] IDENTITY(1,1) NOT NULL,
	[strUserID] [varchar](50) NOT NULL,
	[IsLocalUser] [char](1) NULL,
	[strMD5PWD] [varchar](100) NULL,
	[strUserName] [nvarchar](50) NULL,
	[strPersonalNo] [varchar](20) NULL,
	[strEmail] [varchar](100) NULL,
	[n1Question] [tinyint] NULL,
	[strAnswer] [nvarchar](100) NULL,
	[strPostNo] [varchar](10) NULL,
	[strAddress1] [nvarchar](200) NULL,
	[strAddress2] [nvarchar](200) NULL,
	[strHomePhone] [varchar](20) NULL,
	[strMobilePhone] [varchar](20) NULL,
	[strBirthday] [varchar](20) NULL,
	[IsLunar] [char](1) NULL,
	[IsSMS] [char](1) NULL,
	[IsEmail] [char](1) NULL,
	[n1JoinMotiveType] [tinyint] NULL,
	[n1UserLevel] [tinyint] NULL,
	[n1GroupType] [tinyint] NULL,
	[dtJoinDate] [datetime] NULL,
	[dtLastLogin] [datetime] NULL,
	[strLoginIP] [varchar](30) NULL,
	[IsRemoved] [tinyint] NULL,
	[dtRemoveDate] [datetime] NULL,
	[CodeSex] [tinyint] NULL,
 CONSTRAINT [PK_TB_User_strUserID] PRIMARY KEY CLUSTERED 
(
	[strUserID] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO

IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[TB_User]') AND name = N'IX_TB_User_dtJoinDate')
CREATE NONCLUSTERED INDEX [IX_TB_User_dtJoinDate] ON [dbo].[TB_User] 
(
	[IsRemoved] ASC,
	[dtJoinDate] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
GO

IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[TB_User]') AND name = N'IX_TB_User_IsLocalUser')
CREATE NONCLUSTERED INDEX [IX_TB_User_IsLocalUser] ON [dbo].[TB_User] 
(
	[IsRemoved] ASC,
	[IsLocalUser] ASC,
	[dtJoinDate] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
GO

IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[TB_User]') AND name = N'IX_TB_User_n1GroupType')
CREATE NONCLUSTERED INDEX [IX_TB_User_n1GroupType] ON [dbo].[TB_User] 
(
	[IsRemoved] ASC,
	[n1GroupType] ASC,
	[dtJoinDate] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
GO

IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[TB_User]') AND name = N'IX_TB_User_strUserName')
CREATE NONCLUSTERED INDEX [IX_TB_User_strUserName] ON [dbo].[TB_User] 
(
	[IsRemoved] ASC,
	[strUserName] ASC,
	[dtJoinDate] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
